<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>大奔农庄</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/aui.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/style.css"/>    
    <link rel="stylesheet" href="../../css/swiper.min.css">
    <link rel="stylesheet" href="../../font/iconfont.css">
    
</head>
<body>
	<header class="aui-bar aui-bar-nav top-nav" id="title">
		<a class="aui-pull-left aui-btn"></a> 
		<div class="aui-title" id="db_title">大奔农庄</div>
	</header>
	<div id="db_zhanwei"></div>
	<div class="aui-bar aui-bar-btnn aui-bar-btn-full" style="position: fixed;top: 3.4rem;">
	    <div class="aui-bar-btn-itemm cd_shaixuan zhmx-active" tapmode="" data-item-order="0" onclick="shaixuan(this,7);">全部</div>
	    <div class="aui-bar-btn-itemm cd_shaixuan " tapmode="" data-item-order="1" onclick="shaixuan(this,1);">待付款</div>
	    <div class="aui-bar-btn-itemm cd_shaixuan" tapmode="" data-item-order="2" onclick="shaixuan(this,2);">待发货</div>
   	    <div class="aui-bar-btn-itemm cd_shaixuan" tapmode="" data-item-order="3" onclick="shaixuan(this,3);">待收货</div>
	    <div class="aui-bar-btn-itemm cd_shaixuan" tapmode="" data-item-order="5" onclick="shaixuan(this,6);">退货/售后</div>
	</div>
	<div class="aui-content aui-margin-b-15" style="padding-top: 2.5rem;">
	     <ul class="aui-list aui-media-list" id="orderlist">
	      <!-- 
		    <li class="aui-list-item" style="border-bottom: 15px #f5f5f5 solid;">
				<div class="aui-media-list-item-inner aui-border-b" onclick="openOrderInfo({$vo.id});">
				     <div class="aui-list-item-inner">
				        <div class="aui-list-item-text">
				            <div class="aui-list-item-title">订单号：54564564568456</div>
				            <div class="aui-list-item-right aui-text-warning">待付款</div>
				        </div>
				        <div class="aui-list-item-text db_order_aui-list-item-text">总金额：￥100</div>
				    	<div class="aui-list-item-text db_order_aui-list-item-text">运费：￥10</div>
				    </div>
				</div>
				<div class="aui-media-list-item-inner aui-infoo aui-border-b" style="padding:0rem;">
					<div class="aui-info-item aui-font-size-12 db_order_aui-list-item-text">
				        <span>共5件商品 合计:<span class="aui-text-success">￥1001</span></span>
				    </div>
				</div>
				<div class="aui-info">
				 	<div class="aui-info-item"></div>
				    <div class="aui-info-item">
				    	<div class="aui-btn aui-btn-black aui-btn-block aui-btn-outlined aui-btn-sm anniu-ys" onclick="doOrder({$vo.id},1);">取消订单</div>
				    	<div class="aui-btn aui-btn-warning aui-btn-block aui-btn-outlined aui-btn-sm anniu-ys" onclick="openDopay({$vo.id});">立即付款</div>
				    </div>
				</div>
			</li>
 		-->	
	   	</ul>
		 <div id="wudongtai_box">
		 	<img src="../../image/wudongtai.png" id="wudongtai_img" />
			<p id="wudongtai_txt">暂时没有任何数据</p>
		 </div>	
		 <div class="aui-card-list-footer aui-text-center" id="cd_loading">查看更多</div>   
	</div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript" src="../../script/aui-scroll.js"></script>
<script>
var db_key = 'user',db_user,useParam={},nowpage=1, loadend=false, isloading=false,status=7;
apiready = function() {
	getuser();
	
	//监听登录
    api.addEventListener({
        name: 'login_self'
    }, function(ret, err) {
        getuser();//获取用户信息
        nowpage=1;//页码重新等于1
		loadend = false;
	    loaddata(2);//显示更多数据
    });
    
    //监听退出登录
    api.addEventListener({
        name: 'mylogout'
    }, function(ret, err) {
    	getuser();//获取用户信息
    	loadend = true;
        $api.html($api.byId('orderlist'), '');//清空页面订单数据
        $api.removeCls($api.byId('wudongtai_box'), 'none');//显示无动态框
        $api.html($api.byId('wudongtai_txt'),'用户未登录');
    });
    
	//监听订单状态更改记录
	api.addEventListener({
	    name: 'order_list_change'
	}, function(ret, err) {
		nowpage=1;//页码重新等于1
		loadend = false;
	    loaddata(2);//显示更多数据
	});
	
	loaddata(1);
}
//获取用户储存在本地的数据方法
function getuser() {
    db_user = $api.getStorage(db_key);
}
//监听滚动高度，加载下一页	
var scroll = new auiScroll({
    listen:true, //是否监听滚动高度，开启后将实时返回滚动高度
    distance:10 //判断到达底部的距离，isToBottom为true
},function(ret){
    if (ret.isToBottom) {
        loaddata(1);//显示更多数据
    }
});
//筛选
function shaixuan(obj,type){
	//改变筛选按钮样式
	var $shaixuan_dom = $api.domAll(".cd_shaixuan");
	for (var j = 0; j < $shaixuan_dom.length; j++) {
		$api.removeCls($shaixuan_dom[j], 'zhmx-active');
	}
	$api.addCls(obj,'zhmx-active');
	status = type;//筛选参数值改变
	nowpage=1;//页码重新等于1
	loadend=false;
	loaddata(2);//重新加载数据
} 
//加载内容
function loaddata(flag) {
	if (loadend) {/*api.toast({msg:'1'});*/return;}
    //禁止重复加载
    if (isloading) {/*api.toast({msg:'2'});*/return;}
    else isloading = true;
    api.showProgress();//显示加载进度框
    $api.removeCls($api.byId("cd_loading"),'none');//显示加载中
    useParam.page = nowpage;

	useParam.rtk = RSapi.myrtk;		
	useParam.mytoken = db_user.mytoken;
	useParam.type = status;

	api.ajax({
		url: RSapi.base+RSapi.OrderList,
		method: 'post',
		cache: false,
		timeout: 30,
		dataType: 'json',
		data: { values: useParam },
	}, function(ret, err){
		if(err){
			//api.toast({msg: JSON.stringify(err)});
			api.toast({msg: err.msg});
		}else {
			if (ret.status==1) { 
				//成功了
				nowpage++;//页数加一
				if(flag == 1){ 
					$api.append($api.byId('orderlist'),ret.info);
				}else if(flag == 2){
					$api.html($api.byId('orderlist'),ret.info);
				}		
				$api.addCls($api.byId('wudongtai_box'), 'none');//显示无动态框		
				api.parseTapmode();
				eval('status_'+status+'=true;');
			}else if(ret.status==2){
				//没有内容
				$api.html($api.byId('orderlist'),'');
				loadend = true;
				$api.removeCls($api.byId('wudongtai_box'), 'none');//显示无动态框
				$api.html($api.byId('wudongtai_txt'), ret.info);//显示提示内容
			}else if(ret.status==3){
				//成功了, 但是已经加载完毕
                loadend = true;
                api.toast({msg:ret.info});
			}else {
				//失败了
				api.toast({msg: ret.info});
			}
		}
		$api.addCls($api.byId("cd_loading"),'none');//隐藏加载中
		isloading = false;//加载结束
	});
	api.hideProgress();
}
//订单操作
function doOrder(oid,flag) {
    if(flag == 1){
    	//取消订单操作
    	var do_order_url = RSapi.base+RSapi.OrderQuxiao;
    	var tishi_msg = '您确定要取消订单吗？';
    }else if(flag == 3){
    	//确认收货操作
    	var do_order_url = RSapi.base+RSapi.OrderShouhuo;
    	var tishi_msg = '您确定已经收到货物了吗？';
    }else{
    	api.toast({msg:'操作失败，请联系客服！'});
    }
    
    useParam.rtk = RSapi.myrtk;		
	useParam.mytoken = db_user.mytoken;
	useParam.oid = oid;
    
	//弹出操作确定框
	api.confirm({
	    title: '提醒',
	    msg: tishi_msg,
	    buttons: ['确定', '取消']
	}, function(ret, err) {
		if(ret.buttonIndex == 1){
			api.showProgress();
		    api.ajax({
		        url: do_order_url,
		        method: 'post',
		        cache: false,
		        timeout: 30,
		        dataType: 'json',
		        data: { values: useParam },
		    }, function(ret, err){ 
		        if (err) { 
		            api.alert({msg:err.msg});
		        }else{
		            api.alert({msg:ret.info});
		            //发送订单状态更改成功事件
		            api.sendEvent({
		                name: 'order_list_change',
		                extra: {}
		            });
		        }
		        api.hideProgress();
		    });	
		}	    
	});
}
//打开订单详情
function openOrderInfo(id){
	api.openWin({
        name: 'win_orderinfo',
        url: '../win/orderinfo_win.html',
        pageParam: {oid: id}
    });
}
//打开评论
function openPingjia(id){
	api.openWin({
        name: 'win_pingjia',
        url: '../win/pingjia_win.html',
        pageParam: {oid:id}
    });
}
//打开支付页面
function openDopay(id){
	api.openWin({
        name: 'win_dopay',
        url: '../win/dopay_win.html',
        pageParam: {oid:id}
    });
}
//打开退款页面
function openTuikuan(){
	alert('退款请电话联系：15737928795！');
}
</script>
</html>